package com.matt.controller;

import com.dotflat.fin.PO.WalletFlowPO;
import com.dotflat.fin.PO.WalletPO;
import com.dotflat.fin.domain.Wallet;
import com.dotflat.fin.domain.WalletFlow;
import com.dotflat.fin.service.WalletFlowService;
import com.dotflat.fin.service.WalletService;
import com.dotflat.rest.controller.RestfulBaseController;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.domain.Clientele;
import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.service.ClienteleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Field;

import static com.matt.foundation.constant.CommonConstant.TICKET;

/**
 * @author ：Ron
 * @date ：Created in 11/5/2020 7:36 PM
 */
@RestController
@RequestMapping("/other_system/walletFlow")
@Api(tags = "财务 - 客户钱包流水")
public class OtherSystemWalletFlowController {

    @Autowired
    protected WalletService walletService;

    @Autowired
    protected WalletFlowService baseService;

    @Autowired
    protected MemVerificationCache cache;

    @Autowired
    protected ClienteleService clienteleService;

    @ApiOperation(value = "获取列表")
    @PostMapping("/list")
    public StatusResponse getList(String areaId, String clientId,
                                  WalletFlowPO param, PagerQuery pagerQuery){

        Clientele c = clienteleService.getById(areaId, clientId);

        if (c == null) {
            throw new BusinessException(ErrorCode.CLIENTELE_EXIST, "客户不存在");
        }

        Wallet w = walletService.queryWalletByClientele(c);

        if (w == null){
            throw new BusinessException(ErrorCode.CLIENTELE_EXIST, "钱包不存在");
        }

        Sort sort = Sort.by( "created").descending();

        PageRequest pageRequest = PageRequest.of(pagerQuery.getPageNum(), pagerQuery.getPageSize(), sort);

        return StatusResponse.success( baseService.page(c.getAreaId(), null, param, pageRequest));

    }

}
